Ext.namespace("Task.DownLoad");

Task.DownLoad.panel = function() {
	this.exeId;
	this.store = new Ext.data.Store({
		proxy: new Ext.data.HttpProxy({
			url: '../task/searchTaskUpLoadFile.form?timesnap=' +new Date().getTime()
		}),
		reader: new Ext.data.JsonReader({
			root: 'result',
			totalProperty: 'total',
			fields: ['ACCESSORY_ID', 'ACCESSORY_NAME', 'UPLOAD_DATE','FILE_SIZE','UPLOAD_NAME','ACCESSORY_DESC','USER_NAME']
		}),listeners:{
			 beforeload :{    
	    	  	fn : function(thiz,options){
       	          Ext.apply(thiz.baseParams,
       	          { 
       	          	exeId:this.exeId
       	          });    
              },
              scope:this 
	    	}
		}
	});
	var delTaskUploadFile = new Ext.data.Connection({
		url:'../task/delTaskUploadFile.form?timesnap=' + new Date().getTime(),
		method:'post'
	});
	this.colModel = new Ext.grid.ColumnModel({
	    defaults: {
	        width: 100,
	        sortable: true,
	        align: 'center'
	    },
	    columns: [
			{header: 'TASK_ID', width: 50, hidden: true, dataIndex: 'ACCESSORY_ID'},
			{header: '附件名称', width: 100, dataIndex: 'ACCESSORY_NAME'},
			{header: '附件大小(K)', width: 100, dataIndex: 'FILE_SIZE'},
			{header: '附件上传时间',width: 200, dataIndex: 'UPLOAD_DATE'},
			{header: '备注',width: 100, dataIndex: 'ACCESSORY_DESC'},
			{header: '上传人',width: 100, dataIndex: 'USER_NAME'},
			{header: '操作',width: 50, dataIndex: 'ACCESSORY_ID',renderer:this.downloadUrl}
	    ]
	});
	
	this.gridPanel = new Ext.grid.GridPanel({
		region: 'center',
		cm:this.colModel,
		store:this.store,
		stripeRows: true, 
		sm: new Ext.grid.RowSelectionModel({singleSelect:true}),
        loadMask: {msg: '加载中，请稍候...'},
        bbar:new Ext.PagingToolbar({
			 pageSize: 10,
	         store: this.store,
	         displayInfo: true,
	         displayMsg: '显示第 {0} 条到 {1} 条记录，一共 {2} 条',
	         emptyMsg: "没有记录..."
		}),
		
        viewConfig: { forceFit: true }
        /*listeners:{
        	cellclick:function (grid, rowIndex, columnIndex, e) {
	    		if(columnIndex==4){
	    			Ext.Msg.confirm("信息","确认删除?",function(btn){if(btn=='yes'){
	    				var record = grid.getStore().getAt(rowIndex);
		        		var fieldName = grid.getColumnModel().getDataIndex(columnIndex);
		        		var data = record.get(fieldName);
		        		
		        		var buis_id = data;
		        		Utils.request(delTaskUploadFile,{
		        			params:{
		        			buis_id:buis_id
		        			},
		        			success:function(){
		        				Utils.info('删除成功！');
		        				grid.store.reload();
		        			}
		        		});
		    			
		    			
	    			}else{return false;}});
	    		}else{
	    			return false;
	    		}
        	} 
        }*/
	});
	Task.DownLoad.panel.superclass.constructor.call(this, {
		title:'附件信息',
		layout:'border',
		items:[this.gridPanel],
		listeners:{
			render:this.queryUpfile,
			activate:this.queryUpfile
		}
	});
};
Ext.extend(Task.DownLoad.panel, Ext.Panel, {
	initFeedBack:function(exeId){
		this.exeId = exeId;
	},
	queryUpfile :function(exeId){
		this.store.load({
			params:{
				start : 0,
				limit : 30,
				exeId:this.exeId
			}
		});
	},
	downloadUrl :function(s, m, rec){
		return "<a href='../task/downloadFile.form?fileId="+s+"'>下载</a>";
	}
});


